package com.fg.cloud.manager.service.system.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fg.cloud.common.PageUtils;
import com.fg.cloud.common.construction.Select;
import com.fg.cloud.manager.entry.factory.FactoryEntity;
import com.fg.cloud.manager.entry.product.ProductSkuEntity;
import com.fg.cloud.manager.mapper.system.SystemProductMapper;
import com.fg.cloud.manager.service.system.SystemProductService;

@Service
public class SystemProductServiceImpl implements SystemProductService{

	@Autowired
	private SystemProductMapper systemProductMapper;
	
	@Override
	public void findBySenior(PageUtils<ProductSkuEntity> pageinfo) {
		long total = systemProductMapper.findSeniorCount(pageinfo);
		pageinfo.setTotal(total);
		if(total == 0){
			pageinfo.setData(new ArrayList<ProductSkuEntity>());
		}
		pageinfo.setData(systemProductMapper.findBySenior(pageinfo));
	}

	@Override
	public List<Select> findAllFactory() {
		List<Select> sllist = new ArrayList<Select>();
		List<FactoryEntity> list= systemProductMapper.findAllFactory();
		for(int i= 0;i<list.size();i++){
			sllist.add(new Select(String.valueOf(list.get(i).getId()), list.get(i).getFacName()));
		}
		return sllist;
	}

	@Override
	public List<ProductSkuEntity> findBySenior2(PageUtils<ProductSkuEntity> pageinfo) {
		return systemProductMapper.findBySenior(pageinfo);
	}

	@Override
	@Transactional
	public Long delete(List<Long> id) {
		Long flag = Long.valueOf(0);
		Long sum = systemProductMapper.selectSum(id);
		if(sum == 0){
			flag = systemProductMapper.delete(id);
		}
		return flag;
	}
}
